package com.wsx.ones.cloud.world;

import com.wsx.ones.cloud.config.ServiceBean;
import com.wsx.ones.cloud.feign.FeignService;
import com.wsx.ones.cloud.feign.ProductFeign;
import com.wsx.ones.cloud.product.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by wangshuaixin on 17/5/9.
 */
@RestController
@RequestMapping("/world")
public class WorldController {


    @Autowired
    private FeignService feignService;

    @Autowired
    private ServiceBean serviceBean;

    @Autowired
    private ProductFeign productFeign;

    @RequestMapping(
            value = "/hello/{name}",
            method = {RequestMethod.GET}
    )
    public String hello(@PathVariable String name) {
        //获得配置的参数
        String value = serviceBean.getEurekaClient();
        //服务的调用，get请求
        return feignService.remoteWorld(name);
    }


    @RequestMapping(
            value = "/first",
            method = {RequestMethod.GET}
    )
    public String first(@RequestParam("id") Integer id, @RequestParam("name") String name) {
        String rtn = null;
        Product product = new Product(id, name);
        //服务调用，post请求
        rtn = productFeign.second(product);
        return rtn;
    }

    @RequestMapping(
            value = "/test",
            method = {RequestMethod.POST}
    )
    public String test(Product product) {
        String rtn = null;
        //Product product = new Product(id, name);
        //服务调用，post请求
        rtn = feignService.remoteTestPost(product);
        return rtn;
    }
}
